﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Einstein.Utility
{
    public static class WriteLog
    {
        //日志保存路径，不包括文件名
        private static string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "Log";
        //日志完整路径，包括文件名
        private static string file = filePath +"\\"+ DateTime.Now.ToString("yyyy-MM-dd")+".txt"; 

        public static void Write(string txt)
        {
            try
            {
                //文件不存在，则创建新文件
                if (!System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.CreateDirectory(filePath);
                }

                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(file, true, System.Text.Encoding.UTF8))
                {
                    sw.Write(Environment.NewLine);
                    sw.WriteLine(DateTime.Now.ToShortTimeString());
                    sw.WriteLine(txt);
                }
            }
            catch (Exception ex)
            { 
            }
        }
    }
}
